<template>
  <div class="info-box" v-loading="loading">
    <div class="flex ai-c">
       <router-link to="/user/accountInfo">
      <div class="user-icon">
        <img :src="userinfo.cardpic|nopic" />
      </div>
       </router-link>
      <div class="flex-1 flex jc-sb ai-fs">
      <router-link to="/user/accountInfo">
        <div class="user-info-box">
          <div class="name">{{userinfo.nickname}}</div>
          <span>下午好～</span>
          <div class="huiyuan">普通会员</div>
          <!--<p>修改个人信息 ></p>-->
        </div>
      </router-link>
        <div class="order-box">
          <p>我的订单</p>
          <ul class="flex jc-sb">
            <li class="flex flex-d jc-sb ai-c" @click="getOrderData(0)">
              <img src="@/assets/user/info-icon-1.png" />
              <span :class="{ c_active:0 == status }">待付款</span>
            </li>
            <li class="flex flex-d jc-sb ai-c"  @click="getOrderData(1)">
              <img src="@/assets/user/info-icon-3.png" />
              <span :class="{ c_active:1 == status }">待发货</span>
            </li>
            <li class="flex flex-d jc-sb ai-c" @click="getOrderData(2)">
              <img src="@/assets/user/info-icon-2.png" />
              <span :class="{ c_active:2 == status }">已发货</span>
            </li>
            <li class="flex flex-d jc-sb ai-c" @click="getOrderData(3)">
              <img src="@/assets/user/info-icon-2.png" />
              <span :class="{ c_active:3 == status }">已完成</span>
            </li>
            <li class="flex flex-d jc-sb ai-c" @click="getOrderData(4)">
              <img src="@/assets/user/info-icon-2.png" />
              <span :class="{ c_active:4 == status }">已关闭</span>
            </li>
            <li class="flex flex-d jc-sb ai-c" @click="getOrderData(5)">
              <img src="@/assets/user/info-icon-2.png" />
              <span :class="{ c_active:5 == status }">无效订单</span>
            </li>
            <li class="flex flex-d jc-sb ai-c" @click="getOrderData(999)">
              <img src="@/assets/user/info-icon-4.png" />
              <span :class="{ c_active:999 == status }">全部订单</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- 移动端导航 -->
    <div class="nav-list">
      <div class="flex jc-sb ai-c" @click="navItemClick(999)">
        <span>我的订单</span>
        <img src="@/assets/user/info-icon-4.png" />
      </div>
      <div class="flex jc-sb nav-item">
        <li class="flex flex-d jc-sb ai-c" @click="navItemClick(0)">
          <img src="@/assets/user/info-icon-1.png" />
          <span :class="{ c_active:0 == status }">待付款</span>
        </li>
        <li class="flex flex-d jc-sb ai-c" @click="navItemClick(2)">
          <img src="@/assets/user/info-icon-2.png" />
          <span :class="{ c_active:2 == status }">已付款</span>
        </li>
        <li class="flex flex-d jc-sb ai-c" @click="navItemClick(3)">
          <img src="@/assets/user/info-icon-3.png" />
          <span :class="{ c_active:3 == status }">退款</span>
        </li>
        <li class="flex flex-d jc-sb ai-c" @click="navItemClick(4)">
          <img src="@/assets/user/info-icon-5.jpg" />
          <span :class="{ c_active:3 == status }">收藏</span>
        </li>
      </div>
      <h2>购车服务</h2>
      <ul class="handle-box">
        <li class="flex jc-sb ai-c" @click="goFeedback">
          <div class="left-name">
            <img src="@/assets/user/info-icon-6.jpg"/>
            <span>意见反馈</span>
          </div>
          <i class="el-collapse-item__arrow el-icon-arrow-right"></i>
        </li>
        <li class="flex jc-sb  ai-c" @click="goHelp">
          <div class="flex ai-c left-name">
            <img src="@/assets/user/info-icon-7.jpg"/>
            <span>购车帮助</span>
          </div>
          <i class="el-collapse-item__arrow el-icon-arrow-right"></i>
        </li>
      </ul>
    </div>
    
    <div class="list-box" v-if="list.length > 0">
      <div   class="list-item" v-for="(item,key) in list" :key="`list-${key}`">
        <order-info :orderInfo="item.orderItemList" :orderStatus="status" :payType="item.payType"></order-info>
      </div>

      <el-paginationpageNum background layout="prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange" @prev-click="prePage" @next-click="nextPage" :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="persizes" :total="total"></el-paginationpageNum>
    </div>
    <div class="list-box" v-if="list.length==0">
      <div   class="list-item">
        <div v-if="list.length==0">暂无记录</div>
      </div>
    </div>
  </div>
</template>

<script>
import OrderInfo from "@/components/OrderInfo.vue";
import empty from "../../../utils/common";
export default {
  components: {
    OrderInfo
  },
  data() {
    return {
      currentPage: 1,
      total: 1,
      persizes: 10,
      loading: false,
      userinfo: {},
      status: 0,
      list: [{ productPic: '' }, { productPic: '' }]// 0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单, 7->退款,8 -> 订购                 
    };
  },
  created() {
    this.userinfo = JSON.parse(localStorage.getItem('userinfo'));
    this.getMyOrder();
  },
  methods: {
    getOrderData(type) {
      this.status = type;
      this.getMyOrder();
      console.log(type);
    },
    // getMyRefund(){
    //     let _this = this;
    //     this.$http.get('/returnApply/list',{
    //         page:_this.currentPage,
    //         size:_this.persizes,
    //     }).then(function (response) {
    //         _this.orderlist = response.data;
    //         _this.total = response.data.length;
    //         window.console.log(response);
    //     })
    // },
    getMyOrder() {
      let _this = this;
      this.loading = true;
      let url = '/order/list?pageSize=' + _this.persizes + '&pageNum=' + this.currentPage;
      if (this.status != '999') {
        url += '&status=' + this.status;
      }
      this.$http.get(url).then((response) => {
        this.loading = false;
        if(response.data.list==null){
          this.list = [];
        }else{
          this.list = response.data.list;
        }

        this.currentPage = empty(response.data.pageNum) ? 1 : response.data.pageNum;
        this.total = empty(response.data.total) ? 0 : response.data.total;

      })
    },
    handleSizeChange(val) {
      this.persizes = val;
      this.getMyOrder();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getMyOrder();
    },
    prePage() {
      this.getMyOrder();
    },
    nextPage() {
      this.getMyOrder();
    },
    //移动端导航
    navItemClick(type){
      if(type !== 3 && type !== 4) this.getOrderData(type);
      else {
       if(type === 3) this.$router.push("/user/myRefund");
       else this.$router.push("/user/myCollect");
      }
    },
    goFeedback(){
      this.$router.push("/user/feedback")
    },
    goHelp(){
      this.$router.push("/user/BuyCarHelp")
    }
  },
};
</script>

<style lang="scss" scoped>
.c_active {
  color: red;
  font-weight: bold;
}
.info-box {
  width: 100%;
  padding: 50px;
  box-sizing: border-box;
  .user-icon {
    width: 140px;
    height: 140px;
    background: #f7f7f7;
    border-radius: 50%;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .user-info-box {
    text-align: left;
    padding-left: 20px;
    .name {
      font-size: 20px;
      color: #616161;
    }
    span {
      font-size: 14px;
      color: #929292;
    }
    .huiyuan {
      width: 135px;
      line-height: 24px;
      background-color: #444440;
      border-radius: 12px;
      font-size: 12px;
      color: #f0eda8;
      text-align: center;
      margin: 10px 0 20px;
      cursor: pointer;
    }
    p {
      text-align: center;
      font-size: 12px;
      color: #f0542e;
    }
  }
  .order-box {
    width: 400px;
    p {
      text-align: left;
      margin-bottom: 30px;
    }
    ul {
      padding: 0 10px;
    }
    li {
      height: 80px;
      cursor: pointer;
      img {
        height: 34px;
      }
      &:not(:last-child) {
        img {
          transform: translateY(10px);
        }
      }
      &:last-child {
        img {
          height: 50px;
        }
      }
    }
  }
  // 列表
  .list-box {
    width: 100%;
    margin-top: 50px;

    .list-item {
      margin-left: 10px !important;
      padding: 20px 0;
      border-top: 1px solid #dcdcdc;

      &:last-child {
        border-bottom: 1px solid #dcdcdc;
      }
    }
  }
}
.nav-list {
  display: none;
}

/*手机端*/
@media (min-width: 320px) and (max-width: 800px) {
  .info-box {
    padding: 10px;
    
    .user-icon {
      width: 80px;
      height: 80px;
    }

    .user-info-box {
      .name {
        font-size: 18px;
      }
      .huiyuan {
        margin: 10px 0;
      }
    }
  }
  /*导航按钮*/
  .nav-list {
    display: block;
    padding: 10px 4px;

    span {
      font-size: 18px;
    }
    img {
      width: 36px;
    }
    .nav-item {
      padding-top: 16px;
      padding-bottom: 10px;
      border-bottom: 1px solid #f1f1f1;
      img{
        width: 30px;
      }
      span{
        font-size: 14px;
        font-weight: normal;
        margin-top: 6px;
      }
    }
    h2 {
      text-align: left;
      font-weight: normal;
      font-size: 18px;
      padding: 20px 0 10px;
      border-bottom: 1px solid #f1f1f1;
    }
    .handle-box {
      li {
        padding: 10px 0;
        border-bottom: 1px solid #f1f1f1;
      }
      .left-name {
        img {
          width: 20px;
        }
        span {
          font-size: 14px;
          padding-left: 10px;
        }
      }
    }
    
  }
 
  .order-box {
    display: none;
  }

  .list-box {
    margin-top: 10px !important;
  }
  .list-item {
    padding: 10px 0 !important;
    &:first-child{
      border: 0 !important;
    }
  }
}
</style>
